package jp.ne.hatena.d.digitalsoul.loansyndicate.roles

import jp.ne.hatena.d.digitalsoul.loansyndicate.models.Share

trait Lender {
	
	var limit:BigInt
	
	def draw(amount:BigInt, amountPie:AmountPie, percentagePie:PercentagePie) = {
		amountPie.increase(amount, percentagePie)
        decreaseLimitBy(amount)
	}
	
	def pay(amount:BigInt, amountPie:AmountPie) = {
		amountPie.decrease(amount, amountPie)
		increaseLimitBy(amount)
	}
	
	private def decreaseLimitBy(amount:BigInt) = limit -= amount
	
	private def increaseLimitBy(amount:BigInt) = limit += amount 

}